package com.rc.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.rc.entity.GenTable;
import com.rc.service.GenTableService;
import com.rc.entity.web.PageParam;
import com.rc.entity.web.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.commons.lang3.StringUtils;
import java.util.Map;

@RestController
@Api(tags="table接口")
@RequestMapping("/genTable")
public class GenTableController {

    @Autowired
    private GenTableService genTableService;

    /**
    * 根据id获取对象
    * @param id
    * @return
    */
    @GetMapping("/{id}")
    public GenTable getById(@PathVariable Long id) {
        return genTableService.getById(id);
    }

    /**
    * 分页查询
    * @param pageParam
    * @return
    */
    @PostMapping("/queryByPage")
    public Result queryUserByPage(PageParam pageParam){
        QueryWrapper<GenTable> genTableQueryWrapper = new QueryWrapper<>();
        Map<String, String> queryMap = pageParam.getQueryMap();
        if (StringUtils.isNotBlank(queryMap.get("id"))){
            genTableQueryWrapper.like("id",queryMap.get("id"));
        }
        Page<GenTable> genTablePage = genTableService.page(new Page<>(pageParam.getCurrentPage(), pageParam.getPageSize()), genTableQueryWrapper);
        return Result.SUCCESS(genTablePage);
    }
}
